package com.snail.billing.json;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonWorkRecordLog extends JsonBase {

	private List<RecordLog> recordLogs;

	public JsonWorkRecordLog(String jsonString) {
		super(jsonString);
		try {
			if (getCode() == 1) {
				recordLogs = new ArrayList<RecordLog>();
				JSONArray jsonArray = new JSONObject(jsonString).getJSONArray("data");
				TreeMap<String, RecordLog> treeMap = new TreeMap<String, RecordLog>();
				for (int i = 0; i < jsonArray.length(); i++) {
					RecordLog recordLog = new RecordLog(jsonArray.getString(i));
					if (!recordLog.getOperateDate().equals("0")) {
						treeMap.put(recordLog.getOperateDate(), recordLog);
					}
				}
				for (String key : treeMap.keySet()) {
					recordLogs.add(treeMap.get(key));
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<RecordLog> getRecordLogs() {
		return recordLogs;
	}

	public class RecordLog {
		private String content;
		private String type;
		private String operateDate;

		public RecordLog(String jsonString) {
			try {
				JSONObject json = new JSONObject(jsonString);
				if (json.has("content")) {
					content = json.getString("content");
				}
				if (json.has("type")) {
					type = json.getString("type");
				}
				if (json.has("operateDate")) {
					operateDate = json.getString("operateDate");
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		public String getContent() {
			return content;
		}

		public String getType() {
			return type;
		}

		public String getOperateDate() {
			return operateDate;
		}

	}

}
